

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ab.util.AbViewUtil;
import com.example.administrator.caigou51.EventBusClass.UpdateHidePosition;
import com.example.administrator.caigou51.EventBusClass.UpdateZhuanQuByCatID;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.basic.MaterialListAdapter;
import com.example.administrator.caigou51.recyclerCard.basic.MaterialListView;
import com.example.administrator.caigou51.recyclerCard.card.ZhuangQu1ChildCard;


import de.greenrobot.event.EventBus;


public class ZhuangQu1ChildCardView extends CardItemView<ZhuangQu1ChildCard> {
 	private Context mContext;
    private ImageView imageViewLine;
    private TextView textViewType;
    public ZhuangQu1ChildCardView(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public ZhuangQu1ChildCardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public ZhuangQu1ChildCardView(Context context,
                                  AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }
    @Override
    public void build(final ZhuangQu1ChildCard card) {
        // TODO Auto-generated method stub
        super.build(card);
        card.setView(this);
        imageViewLine= (ImageView) findViewById(R.id.imageViewLine);
        textViewType= (TextView) findViewById(R.id.textViewType);
        textViewType.setText(card.getSubCatEntity().getCatname());
        if (!card.ischecked())
        {
            imageViewLine.setVisibility(View.INVISIBLE);
            textViewType.setTextColor(getResources().getColor(R.color.color_333333));

        }else
        {
            imageViewLine.setVisibility(View.VISIBLE);
            textViewType.setTextColor(getResources().getColor(R.color.color_1ca146));

        }
        MaterialListView listView=card.getMaterialListView();
        final MaterialListAdapter materialListAdapter= (MaterialListAdapter) listView.getAdapter();

        if (card.getPosition()==materialListAdapter.getItemCount()-1)
        {
            RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) this.getLayoutParams();
            lp.setMargins(0,0, AbViewUtil.scaleValue(mContext,100),0);
        }else
        {
            RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) this.getLayoutParams();
            lp.setMargins(0,0, 0,0);
        }

        setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


               /* for (int i=0;i<materialListAdapter.getItemCount();i++)
                {
                    ZhuangQu1ChildCard zhuangQu1ChildCard = (ZhuangQu1ChildCard) materialListAdapter.getCard(i);
                    zhuangQu1ChildCard.setIschecked(false);
                }
                card.setIschecked(true);
                EventBus.getDefault().post(new UpdateHidePosition(card.getPosition()));
                materialListAdapter.notifyDataSetChanged();*/
                EventBus.getDefault().post(new UpdateZhuanQuByCatID(card.getSubCatEntity().getCatid(),card.getPosition()));
            }
        });


    }
}
